
//舆情
var d = ''
$.ajax({
  url:"http://localhost:8888/bigDateApi/data/findEvaInfo",
  type : "get",
  async : false,
  success:function (result){
    d =  result.data
    console.log(result)
  }
})

// 循环追加到ul的li后面
var element = document.querySelectorAll(".con.clearfix ul");
var q = 0;
var tr = true;
// 每次循环是循环的 ul里面的 li 采用 获取到ul列表后循环追加 2022-3-17 lxxtwoing
for (let i = 0; i <= 4; i++) {
  if (tr){
    if (i===4){
      i=0
    }
    element[i].innerHTML += ent(d[q])
    q++;
    if(q===d.length){
      tr = false
    }
  }
}
function ent(obj){
  return`
    <li class="active">
      <div class="tit clearfix">
        <span class="fl">
          <b class="user-name">${obj.name}</b>
          <b class="time-show">${obj.time}</b>
        </span>
        <span class="fr">
          <b class="icon give-like fr">${obj.heart}</b>
          <b class="icon comments fr">${obj.sub_comment}</b>
        </span>
      </div>
      <p>${obj.info}</p>
    </li>
  `
}



// 柱形图

var bar = echarts.init(document.getElementById('bar'));
var num = 4;
var data = ''
$.ajax({
  url:"http://localhost:8888/bigDateApi/data/findTendency",
  type : "get",
  async : false,
  success:function (result){
    data =  result.data
  }
})
// console.log(data)
var dayData = []
// 将天数灌入数组
for (let i = 0; i < data.length; i++) {
  dayData[i] =
    {
      "datetime": data[i].time,
      "cnt": data[i].quantity
    }
}

var optionBar = {
  grid: {
    top: 50,
    bottom: '15%',
  },
  legend: {
    data: ['交易量'],
    right: '0%',
    itemWidth: 18,
    itemHeight: 12,
    textStyle: {
      color: '#fff'
    }
  },
  xAxis: [{
    data: (function () {
      var tt = [];
      for (var i = 0; i < num; i++) {
        tt.push(dayData[i].datetime);
      }
      // todo: 月份
      // console.log("tt",tt);
      return tt;
    })(),
    axisLine: {
      show: false,
      lineStyle: {
        color: '#07bffb'
      }
    },
    axisTick: {
      show: false
    },
    axisLabel: {
      interval: 0
    }
  }],
  yAxis: [{
    name: "批次",
    axisLine: {
      show: false,
      lineStyle: {
        color: '#07bffb'
      }
    },
    splitLine: {
      show: false
    },
    axisTick: {
      show: false
    },
    // interval:100000,
    min: 0,
    max: 100000,
    // position: 'bottom'
  }],
  series: [{
    name: '交易量',
    type: 'bar',
    label: {
      normal: {
        show: true,
        position: 'top',
        color: '#fff'
      }
    },
    barWidth: '40%',
    barGap: 1,
    itemStyle: {
      normal: {
        color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
          offset: 0.5,
          color: '#00fecc'
        }, {
          offset: 0.7,
          color: '#2690cf'
        }], false)
      }
    },
    data: (function () {
      var tt = [];
      for (var i = 0; i < num; i++) {
        tt.push(dayData[i].cnt)
      }
      return tt;
    })(),
  }]
}
var base = "http://localhost:8888/bigDateApi/data/";
var findBestPbHouse = "findBestPbhouse";
var findBestPbHouseUrl = base+findBestPbHouse;

var pressData;
$.ajax({
  type : 'get',
  datatype : 'json',
  async:false,
  url:findBestPbHouseUrl,
  success:function (result){
    pressData = result.data
    // todo:不知道干啥的数据
    // console.log("result", result)
  }
})

var rankUl = $(".left-bottom .con ul");

var pressName = "";
var pic = "";

rankUl.each(function(index, item) {
  var len = item.children.length;
  for (var i = 0; i < len; i++) {
    pressName = pressData[i]['pbhouse_name'];
    pic = pressData[i]['total_batch'];

    $(item.children[i])
        .find(".name-in")
        .text(pressName);
    $(item.children[i])
        .find(".rank-value")
        .text(pic);
  }
});




bar.setOption(optionBar);

setInterval(function () {
  // debugger
  num++;
  if (num > 11) {
    num = 0;
  }
  var data0 = optionBar.series[0].data;
  data0.shift();
  // todo: 总交易量趋势监控
  data0.push(dayData[num]["cnt"]);

  // console.log("data0",data0);
  // console.log("dayData",dayData);
  optionBar.xAxis[0].data.shift();
  optionBar.xAxis[0].data.push(dayData[num]["datetime"]);

  bar.setOption(optionBar);
}, 2100);

// 馆藏行高和动效

var lineH = $('.book-collection li').height();
$('.book-collection li').css('line-height', lineH + 'px');

var pressNum = -1;

var rankbUl = $('.book-collection ul');
var rankbLen = rankbUl.children().length;
setInterval(function () {
  pressNum++;
  if (pressNum >= 8) {
    $('.book-collection li:lt(8)').hide();
  }
  if (pressNum > rankbLen) {
    pressNum = -1;
    $('.book-collection li:lt(8)').show();
  }
  var curLi = rankbUl.children().eq(pressNum);
  curLi.children('.book-rank').addClass('briRotate');
  curLi.siblings().children('.book-rank').removeClass('briRotate');
}, 1000);

// 网络舆情切换
var yuNum = -1;
var yuLen = $('.public-opinion ul:eq(0) li').length;

setInterval(function () {
  yuNum++;
  if (yuNum >= yuLen) {
    yuNum = 0;
  }

  $('.public-opinion ul:eq(0) li').eq(yuNum).show();
  $('.public-opinion ul:eq(0) li').eq(yuNum).siblings().hide();

  $('.public-opinion ul:eq(1) li').eq(yuNum).show();
  $('.public-opinion ul:eq(1) li').eq(yuNum).siblings().hide();

  $('.public-opinion ul:eq(2) li').eq(yuNum).show();
  $('.public-opinion ul:eq(2) li').eq(yuNum).siblings().hide();

  $('.public-opinion ul:eq(3) li').eq(yuNum).show();
  $('.public-opinion ul:eq(3) li').eq(yuNum).siblings().hide();

}, 2000);

// 物流信息
var logistLen = $('.logistics .con-in').length;
var logNum = -1;
setInterval(function () {
  logNum++;
  if (logNum >= logistLen) {
    logNum = 0;
  }

  $('.logistics .con-in').eq(logNum).show();
  $('.logistics .con-in').eq(logNum).siblings().hide();

}, 4000);


